<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" >
function passData(){
	var domain = 'http://www.c.com:8080';
	var str = document.getElementById('msg').value;
	//alert(str);
	//注意：window.opener 实际上就是通过window.open打开的窗体的父窗体
	var parentWindow = window.opener;
	/**
	 *	postMessage:前面的window是要接收message的window对象
	 *	domain:接收message信息的窗口的  协议：//域名:端口
	 **/
	parentWindow.postMessage(str,domain);
}


//----------------------------接收父页面传递过来的内容---------------------------------------

//接收postMessage传递过来的数据
	if(window.addEventListener){
		window.addEventListener('message',receiveMessage,false);
	}else{
		 window.attachEvent('message', receiveMessage); 
	}
	
	function receiveMessage(e){
		var div = document.getElementById('subDiv');
		div.innerHTML = "origin-->" + e.origin + "-----------------  data-->"
				+ e.data;
	}

</script>
<body>

待传递的数据内容：<input type='text' id='msg' value=''/><br/>
<input type='button' value='数据传递' onclick='passData()'/>
<div id='subDiv'></div>

</body>
</html>